/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pgentity.prize;

import config.PGConfig;
import java.util.Collections;
import java.util.Map;
import logging.report.UserAction;
import pgentity.EntityContext;
import pgentity.Minigame;
import share.PGHelper;

/**
 *
 * @author Salm
 */
public class MinigameTurnPrize implements PGPrize {
    private final int nTurn;

    public MinigameTurnPrize(int nTurn) {
        this.nTurn = nTurn;
    }
    
    @Override
    public Map<String, Object> award(EntityContext context, long now) {
        Minigame miniGame = Minigame.getMinigame(context.getUid());
        miniGame.incTurn(nTurn);
        
        return Collections.EMPTY_MAP;
    }

    @Override
    public boolean canPrize(EntityContext context, long now) {
        int maxStock = PGConfig.inst().miniGame().getMaxStock();
        Minigame miniGame = Minigame.getMinigame(context.getUid());
        int cTurn = miniGame.getTurn();
        return cTurn + nTurn <= maxStock;
    }
    
    public static class Factory implements IPrizeFactory
    {
        private Factory()
        {
            super();
        }
        
        private static final Factory inst = new Factory();
        
        public static Factory inst()
        {
            return inst;
        }
        
        @Override
        public PGPrize createPrize(Object prizeData, UserAction src) {
            return new MinigameTurnPrize(PGHelper.toInteger(prizeData));
        }   
    }
}
